using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace DesigningViews.Helpers
{
	public static class HtmlExtensions
	{
		public static string ActionLink<TController>(this HtmlHelper helper, string linkText,
											 Expression<Func<TController, object>> actionExpression)
		{
			string controllerName = typeof(TController).GetControllerName();
			string actionName = actionExpression.GetActionName();

			return helper.ActionLink(linkText, actionName, controllerName);
		}

		public static string LabelWithTextBox(this HtmlHelper helper, string name, object value)
		{
			string label = string.Format("<label for={0}>{1}:</label>", name, name);
			string textBox = helper.TextBox(name, value);

			return label + textBox;
		}
	}
}